package com.gxaedu.rbac.config;

import com.gxaedu.rbac.interceptor.LoginInterceptor;
import com.gxaedu.rbac.interceptor.RbacInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author:Teacher黄
 * @date:Created at 2020/04/21
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {



    @Bean
    public RbacInterceptor rbacInterceptor(){
        return new RbacInterceptor();
    }


    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册了login的拦截器
        registry.addInterceptor(new LoginInterceptor())
                // 拦截的路径
                .addPathPatterns("/**")
                // 放行的路径
                .excludePathPatterns("/login/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/lib/**")
                .excludePathPatterns("/fonts/**");

        // 注册权限的拦截器
        registry.addInterceptor(rbacInterceptor())
                // 拦截的路径
                .addPathPatterns("/**")
                // 放行的路径
                .excludePathPatterns("/login/**")
                .excludePathPatterns("/index")
                .excludePathPatterns("/welcome")
                .excludePathPatterns("/menu")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/lib/**")
                .excludePathPatterns("/fonts/**");
    }
}
